/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.bean.InBillBean;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class InBillListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"InBillList.xls\"");
		HSSFSheet sheet = workbook.createSheet("list");
		HSSFRow r = sheet.createRow(0);
		HSSFCell c = r.createCell(0);
		r.createCell(1);
		r.createCell(2);
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7);
		c.setCellValue(new HSSFRichTextString("入库金额合计："
				+ model.get("costTotal").toString()));
		sheet.addMergedRegion(new Region(0, 0, 0, 7));
		r = sheet.createRow(1);
		r.createCell(0).setCellValue(new HSSFRichTextString("单号"));
		r.createCell(1).setCellValue(new HSSFRichTextString("入库日期"));
		r.createCell(2).setCellValue(new HSSFRichTextString("仓库名称"));
		r.createCell(3).setCellValue(new HSSFRichTextString("入库类型"));
		r.createCell(4).setCellValue(new HSSFRichTextString("供方单位"));
		r.createCell(5).setCellValue(new HSSFRichTextString("备注"));
		r.createCell(6).setCellValue(new HSSFRichTextString("经办人"));
		r.createCell(7).setCellValue(new HSSFRichTextString("状态"));
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		List list = (List) model.get("list");

		for (int os = 0; os < list.size(); ++os) {
			InBillBean b = (InBillBean) list.get(os);
			String status = "";
			if (b.getInBill().getExamined().equals("Y")) {
				status = "已审核";
			} else {
				status = "未审核";
			}

			r = sheet.createRow(os + 2);
			r.createCell(0).setCellValue(
					new HSSFRichTextString(b.getInBill().getBillCode()));
			r.createCell(1)
					.setCellValue(
							new HSSFRichTextString(sf.format(b.getInBill()
									.getInDate())));
			r.createCell(2)
					.setCellValue(new HSSFRichTextString(b.getStoName()));
			r.createCell(3).setCellValue(
					new HSSFRichTextString(b.getInTypeName()));
			r.createCell(4).setCellValue(
					new HSSFRichTextString(b.getOffererName()));
			r.createCell(5).setCellValue(
					new HSSFRichTextString(b.getInBill().getMark()));
			r.createCell(6).setCellValue(
					new HSSFRichTextString(b.getInBill().getManagerName()));
			r.createCell(7).setCellValue(new HSSFRichTextString(status));
		}

		ServletOutputStream arg12 = response.getOutputStream();
		workbook.write(arg12);
		arg12.flush();
		arg12.close();
	}
}